package com.itheima.server.controller;

import com.itheima.server.service.MessagesService;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;


    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = messagesService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }


    /**
     * 接口名称：联系人添加
     * 接口路径：POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String,Long> paramMap) {
        Long friendId = paramMap.get("userId");
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }


    /**
     *接口名称：联系人列表
     * 接口路径：GET/messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,String keyword) {
       PageResult pageResult =  messagesService.findFriends(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }
}
